package o;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.RemoteException;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appmarket.framework.coreservice.Status;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailHiddenBean;
import com.huawei.appmarket.service.distribution.authentication.bean.AgdSecurityVerificationResponse;
import com.huawei.appmarket.service.distribution.minidetail.MiniDetailActivityProtocol;
import com.huawei.appmarket.service.distribution.minidetail.MiniDetailActivityProtocol.Request;
import com.huawei.appmarket.service.externalapi.secureactivity.SecureProxyActivity;
import com.huawei.appmarket.service.externalservice.distribution.download.response.TaskOperationResponse;
import java.util.ArrayList;
import o.dxq.c;

public class dxp {
    private dgz ˊ;
    private AgdSecurityVerificationResponse ˋ = new AgdSecurityVerificationResponse();
    private TaskOperationResponse ˎ;
    private dxn ˏ;
    private Context ॱ;

    public dxp(@NonNull Context context, @NonNull TaskOperationResponse taskOperationResponse, @NonNull dgz o_dgz) {
        this.ॱ = context;
        this.ˎ = taskOperationResponse;
        this.ˊ = o_dgz;
    }

    public void ॱ(@NonNull dxn o_dxn) {
        Logger.ˎ("DldDistributionManager", "show mini detail instant!");
        this.ˏ = o_dxn;
        cjo miniDetailActivityProtocol = new MiniDetailActivityProtocol();
        Request request = new Request();
        request.ͺ(dph.ˋ().ˊ(o_dxn.ʼ()));
        request.ॱ(false);
        request.ॱˊ(dxq.ˊ(o_dxn));
        request.ˏ(this.ˏ.ˋ());
        request.ॱ(this.ˏ.ॱˊ());
        miniDetailActivityProtocol.ˋ(request);
        cjm o_cjm = new cjm("mini.detail", miniDetailActivityProtocol);
        Intent ॱ = o_cjm.ॱ();
        ArrayList arrayList = new ArrayList();
        arrayList.add(o_dxn.ͺ());
        ॱ.putParcelableArrayListExtra("start_download_request", arrayList);
        ˎ(6, SecureProxyActivity.ˎ(this.ॱ, o_dxn.ˏ(), o_cjm));
    }

    public void ˋ(dxn o_dxn, AgdSecurityVerificationResponse agdSecurityVerificationResponse) {
        if (o_dxn == null || agdSecurityVerificationResponse == null) {
            ॱ(13);
            return;
        }
        this.ˏ = o_dxn;
        this.ˋ = agdSecurityVerificationResponse;
        int ˊ = agdSecurityVerificationResponse.ˊ();
        Logger.ˎ("DldDistributionManager", "distribution way:" + ˊ);
        switch (ˊ) {
            case 0:
                ˏ();
                return;
            case 1:
                ˊ(false);
                return;
            case 2:
                ˊ();
                return;
            case 3:
                ˎ(true);
                return;
            case 4:
                ˎ(false);
                return;
            default:
                Logger.ˎ("DldDistributionManager", "unknow distribution way!");
                ॱ(13);
                return;
        }
    }

    private void ˊ() {
        DetailHiddenBean ॱ = dxq.ॱ(this.ˋ);
        if (ॱ == null) {
            Logger.ˎ("DldDistributionManager", "downloadbean is null!");
            ॱ(17);
        } else if (ˏ(ॱ)) {
            SessionDownloadTask ˋ = dvt.ˏ().ˋ(ॱ.ॱـ());
            if (ˋ == null) {
                ˊ(true);
            } else if (ˋ.ˈ() == 2) {
                ˊ(false);
            } else if (ˋ.ˈ() == 6 || ˋ.ˈ() == -1) {
                if (!ˋ(ˋ)) {
                    ˊ(ˋ);
                }
                ˊ(true);
            }
        } else {
            ˊ(false);
        }
    }

    private boolean ˏ(@NonNull DetailHiddenBean detailHiddenBean) {
        if ((detailHiddenBean.ˌ() & 2) == 0 && ˎ(detailHiddenBean)) {
            return true;
        }
        Logger.ˎ("DldDistributionManager", "can't download because of BtnDisable:" + detailHiddenBean.ˌ() + "or lower versionCode:" + detailHiddenBean.ˎˎ());
        return false;
    }

    private boolean ˎ(@NonNull DetailHiddenBean detailHiddenBean) {
        try {
            if (this.ॱ.getPackageManager().getPackageInfo(detailHiddenBean.ॱـ(), 0).versionCode < Integer.parseInt(detailHiddenBean.ˎˎ())) {
                return true;
            }
        } catch (NameNotFoundException e) {
            Logger.ˎ("DldDistributionManager", "can not find local installed package: " + detailHiddenBean.ॱـ());
            return true;
        } catch (NumberFormatException e2) {
            Logger.ˎ("DldDistributionManager", "parse versioncode error: NumberFormatException");
        }
        return false;
    }

    private void ˎ(final boolean z) {
        final DetailHiddenBean ॱ = dxq.ॱ(this.ˋ);
        if (ॱ == null) {
            Logger.ˎ("DldDistributionManager", "downloadbean is null!");
            ॱ(17);
        } else if (ˏ(ॱ)) {
            SessionDownloadTask ˋ = dvt.ˏ().ˋ(ॱ.ॱـ());
            if (ˋ == null) {
                new dxm(ॱ.ॱˌ()).execute(new Void[0]);
                dxq.ˏ(ॱ, new c(this) {
                    final /* synthetic */ dxp ॱ;

                    public void ˎ(@Nullable SessionDownloadTask sessionDownloadTask) {
                        if (sessionDownloadTask != null) {
                            this.ॱ.ˋ(z, sessionDownloadTask);
                            this.ॱ.ˊ(ॱ, sessionDownloadTask, 0, false);
                            return;
                        }
                        this.ॱ.ॱ(8);
                    }
                });
            } else if (ˋ.ˈ() == 6 || ˋ.ˈ() == -1) {
                if (!ˋ(ˋ)) {
                    ˊ(ˋ);
                }
                ˊ(ॱ, ˋ, ˋ.ʼॱ(), true);
            } else if (ˋ(ˋ)) {
                ॱ(0);
            } else {
                ॱ(18);
            }
            cvt o_dgt = new dgt("agd-install");
            o_dgt.ˋ(this.ˏ.ˊ());
            o_dgt.ˊ(this.ˏ.ʻ());
            cfw.ˎ(o_dgt, new dgo("DldDistributionManager"));
        } else {
            ˊ(false);
        }
    }

    private void ˊ(DetailHiddenBean detailHiddenBean, SessionDownloadTask sessionDownloadTask, int i, boolean z) {
        if (dxi.ॱ(this.ॱ, this.ˏ.ˋ(), this.ˏ.ॱˊ())) {
            String str = null;
            if (!z) {
                str = dph.ˋ().ˊ(sessionDownloadTask);
            }
            ˎ(6, SecureProxyActivity.ˎ(this.ॱ, this.ˏ.ˏ(), dxi.ॱ(detailHiddenBean.ॱـ(), detailHiddenBean.ˉ(), i, str, z)));
            return;
        }
        ॱ(0);
        sessionDownloadTask.ˋॱ(8);
        if (z) {
            dvt.ˏ().ˊ(sessionDownloadTask.ʾ());
        } else {
            dvt.ˏ().ॱ(sessionDownloadTask, false);
        }
    }

    private boolean ˋ(SessionDownloadTask sessionDownloadTask) {
        Object ॱˎ = sessionDownloadTask.ॱˎ("mediaPkg");
        Object ॱˎ2 = sessionDownloadTask.ॱˎ("callerPkg");
        return (!TextUtils.isEmpty(ॱˎ) && ॱˎ.equals(this.ˏ.ˏ())) || (!TextUtils.isEmpty(ॱˎ2) && ॱˎ2.equals(this.ˏ.ˊ()));
    }

    private void ˋ(boolean z, SessionDownloadTask sessionDownloadTask) {
        sessionDownloadTask.ॱˊ(dxq.ˊ(this.ˏ));
        sessionDownloadTask.ˋॱ(8);
        sessionDownloadTask.ˊ(z);
        if (dkb.ˏ(sessionDownloadTask) < 157286400 && this.ˏ.ˎ() == 1 && !dxi.ˏ(this.ˏ.ˋ())) {
            sessionDownloadTask.ˏ(true);
        }
    }

    private void ˊ(boolean z) {
        if (dxq.ˋ(this.ˋ)) {
            dxl.ˋ(this.ˋ);
            dxq.ˊ(this.ˋ);
            try {
                String toJson = this.ˋ.toJson();
                cjo miniDetailActivityProtocol = new MiniDetailActivityProtocol();
                Request request = new Request();
                request.ᐝॱ(toJson);
                request.ॱˊ(dxq.ˊ(this.ˏ));
                request.ͺ(dph.ˋ().ˊ(this.ˏ.ʼ()));
                request.ॱ(z);
                request.ˏ(this.ˏ.ˋ());
                request.ॱ(this.ˏ.ॱˊ());
                miniDetailActivityProtocol.ˋ(request);
                ˎ(6, SecureProxyActivity.ˎ(this.ॱ, this.ˏ.ˏ(), new cjm("mini.detail", miniDetailActivityProtocol)));
                return;
            } catch (IllegalAccessException e) {
                Logger.e("DldDistributionManager", "response convert to json fail: IllegalAccessException");
                ॱ(13);
                return;
            }
        }
        Logger.ˎ("DldDistributionManager", "mini detail data is null!");
        ॱ(17);
    }

    private void ˏ() {
        cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
        AppDetailActivityProtocol.Request request = new AppDetailActivityProtocol.Request();
        request.ˋ(drj.ॱ(this.ˏ.ʼ()));
        request.ˎ(true);
        appDetailActivityProtocol.ˏ(request);
        ˎ(6, SecureProxyActivity.ˎ(this.ॱ, this.ˏ.ˏ(), new cjm("appdetail.activity", appDetailActivityProtocol)));
    }

    private void ˊ(SessionDownloadTask sessionDownloadTask) {
        if (TextUtils.isEmpty(this.ˏ.ˏ())) {
            sessionDownloadTask.ˎ("mediaPkg", null);
        } else {
            sessionDownloadTask.ˎ("mediaPkg", this.ˏ.ˏ());
        }
        if (TextUtils.isEmpty(this.ˏ.ʻ())) {
            sessionDownloadTask.ˎ("referrer", null);
        } else {
            sessionDownloadTask.ˎ("referrer", dof.ˎ(this.ˏ.ʻ()));
        }
        if (TextUtils.isEmpty(this.ˏ.ᐝ())) {
            sessionDownloadTask.ˎ("advInfo", null);
        } else {
            sessionDownloadTask.ˎ("advInfo", this.ˏ.ᐝ());
        }
        sessionDownloadTask.ˎ("advPlatform", String.valueOf(this.ˏ.ˎ()));
        sessionDownloadTask.ˎ("contentId", this.ˏ.ॱ());
        sessionDownloadTask.ˎ("callerPkg", this.ˏ.ˊ());
        sessionDownloadTask.ˎ("downloadFlags", String.valueOf(this.ˏ.ॱॱ()));
    }

    private void ˎ(int i, PendingIntent pendingIntent) {
        Status status = new Status(i);
        status.ˏ(this.ˎ);
        status.ˊ(pendingIntent);
        try {
            this.ˊ.ॱ(status);
        } catch (RemoteException e) {
            Logger.e("DldDistributionManager", "distribution error: RemoteException");
        }
    }

    private void ॱ(int i) {
        Status status = new Status(i);
        status.ˏ(this.ˎ);
        try {
            this.ˊ.ॱ(status);
        } catch (RemoteException e) {
            Logger.e("DldDistributionManager", "distribution error: RemoteException");
        }
    }
}
